home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / TSPLIT.FRM < prev    next >
Text File  |  1997-06-14  |  9KB  |  288 lines

  1. VERSION 5.00
  2. Begin VB.Form FTestSplitter 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Test Splitters"
  5.    ClientHeight    =   5532
  6.    ClientLeft      =   1092
  7.    ClientTop       =   3516
  8.    ClientWidth     =   6876
  9.    ClipControls    =   0   'False
  10.    DrawStyle       =   6  'Inside Solid
  11.    Icon            =   "TSPLIT.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MouseIcon       =   "TSPLIT.frx":0CFA
  14.    PaletteMode     =   1  'UseZOrder
  15.    ScaleHeight     =   5532
  16.    ScaleWidth      =   6876
  17.    Begin VB.TextBox txtB 
  18.       Height          =   1260
  19.       Left            =   3588
  20.       MultiLine       =   -1  'True
  21.       TabIndex        =   4
  22.       Text            =   "TSPLIT.frx":0F0C
  23.       Top             =   2268
  24.       Visible         =   0   'False
  25.       Width           =   2820
  26.    End
  27.    Begin VB.TextBox txtA 
  28.       Height          =   1260
  29.       Left            =   225
  30.       MultiLine       =   -1  'True
  31.       TabIndex        =   3
  32.       Text            =   "TSPLIT.frx":0F28
  33.       Top             =   1995
  34.       Visible         =   0   'False
  35.       Width           =   3420
  36.    End
  37.    Begin VB.ListBox lstB 
  38.       Height          =   816
  39.       Left            =   4176
  40.       MousePointer    =   1  'Arrow
  41.       TabIndex        =   1
  42.       Top             =   720
  43.       Visible         =   0   'False
  44.       Width           =   1875
  45.    End
  46.    Begin VB.ListBox lstA 
  47.       Height          =   624
  48.       Left            =   240
  49.       MousePointer    =   1  'Arrow
  50.       TabIndex        =   0
  51.       Top             =   765
  52.       Visible         =   0   'False
  53.       Width           =   3225
  54.    End
  55.    Begin VB.PictureBox pbBack 
  56.       AutoRedraw      =   -1  'True
  57.       AutoSize        =   -1  'True
  58.       ClipControls    =   0   'False
  59.       Height          =   2928
  60.       Left            =   2640
  61.       Picture         =   "TSPLIT.frx":0F56
  62.       ScaleHeight     =   2880
  63.       ScaleWidth      =   3840
  64.       TabIndex        =   2
  65.       Top             =   1152
  66.       Visible         =   0   'False
  67.       Width           =   3888
  68.    End
  69.    Begin VB.PictureBox pbB 
  70.       AutoRedraw      =   -1  'True
  71.       Height          =   3120
  72.       Left            =   3255
  73.       Picture         =   "TSPLIT.frx":A5D8
  74.       ScaleHeight     =   3072
  75.       ScaleWidth      =   3072
  76.       TabIndex        =   6
  77.       Top             =   1425
  78.       Visible         =   0   'False
  79.       Width           =   3120
  80.    End
  81.    Begin VB.PictureBox pbA 
  82.       Height          =   3870
  83.       Left            =   195
  84.       Picture         =   "TSPLIT.frx":1265A
  85.       ScaleHeight     =   3828
  86.       ScaleWidth      =   3828
  87.       TabIndex        =   5
  88.       Top             =   870
  89.       Visible         =   0   'False
  90.       Width           =   3870
  91.    End
  92.    Begin VB.Menu mnuOption 
  93.       Caption         =   "&Options"
  94.       Begin VB.Menu mnuVertical 
  95.          Caption         =   "&Vertical"
  96.       End
  97.       Begin VB.Menu mnuPicture 
  98.          Caption         =   "&Background Picture"
  99.       End
  100.       Begin VB.Menu mnuAutoSize 
  101.          Caption         =   "&Auto Size"
  102.          Checked         =   -1  'True
  103.       End
  104.       Begin VB.Menu mnuControl 
  105.          Caption         =   "&Control"
  106.          Begin VB.Menu mnuControls 
  107.             Caption         =   "&List Boxes"
  108.             Checked         =   -1  'True
  109.             Index           =   0
  110.          End
  111.          Begin VB.Menu mnuControls 
  112.             Caption         =   "&Text Boxes"
  113.             Index           =   1
  114.          End
  115.          Begin VB.Menu mnuControls 
  116.             Caption         =   "&Picture Box"
  117.             Index           =   2
  118.          End
  119.       End
  120.    End
  121. End
  122. Attribute VB_Name = "FTestSplitter"
  123. Attribute VB_GlobalNameSpace = False
  124. Attribute VB_Creatable = False
  125. Attribute VB_PredeclaredId = True
  126. Attribute VB_Exposed = False
  127. Option Explicit
  128.  
  129. Private split As New CSplitter
  130. Private ctlNW  As Object, ctlSE As Object
  131. Private ordControl As Integer
  132.  
  133. Private Sub cboSplit_Click()
  134.     NewSplit
  135. End Sub
  136.  
  137. Private Sub mnuControls_Click(Index As Integer)
  138.     Dim i As Integer
  139.     ordControl = Index
  140.     For i = 0 To 2
  141.         mnuControls(i).Checked = IIf(i = Index, vbChecked, vbUnchecked)
  142.     Next
  143.     NewSplit
  144. End Sub
  145.  
  146. Private Sub mnuPicture_Click()
  147.     mnuPicture.Checked = Not mnuPicture.Checked
  148.     NewSplit
  149. End Sub
  150.  
  151. Private Sub mnuAutoSize_Click()
  152.     mnuAutoSize.Checked = Not mnuAutoSize.Checked
  153.     NewSplit
  154. End Sub
  155.  
  156. Private Sub mnuVertical_Click()
  157.     mnuVertical.Checked = Not mnuVertical.Checked
  158.     NewSplit
  159. End Sub
  160.  
  161. Private Sub Form_Load()
  162.     Dim iX As Integer
  163.     For iX = 1 To 200
  164.         lstA.AddItem "List Item Number " & iX
  165.         lstB.AddItem "List Item Number " & iX
  166.     Next iX
  167.     Show
  168.     With pbBack
  169.         .Visible = True
  170.         .Left = (ScaleWidth / 2) - (.Width / 2)
  171.         .Top = (ScaleHeight / 2) - (.Height / 2)
  172.     End With
  173.     NewSplit
  174. End Sub
  175.  
  176. Sub NewSplit()
  177.     Set split = Nothing
  178.     
  179.     ' This is unnecessarily complicated because of multiple surfaces
  180.     ' and options; in real programs you normally choose options at
  181.     ' design time
  182.     
  183.     If Not ctlNW Is Nothing Then ctlNW.Visible = False
  184.     If Not ctlSE Is Nothing Then ctlSE.Visible = False
  185.     
  186.     Select Case ordControl
  187.     Case 0 ' List boxes
  188.         ' List boxes control their own borders, so bottom
  189.         ' border may look too large
  190.         Set ctlNW = lstA
  191.         Set ctlSE = lstB
  192.     Case 1 ' Text boxes
  193.         Set ctlNW = txtA
  194.         Set ctlSE = txtB
  195.     Case 2 ' Picture boxes
  196.         Set ctlNW = pbA
  197.         Set ctlSE = pbB
  198.     End Select
  199.     If mnuPicture.Checked Then
  200.         pbBack.Visible = True
  201.         Set ctlNW.Container = pbBack
  202.         Set ctlSE.Container = pbBack
  203.         ctlNW.Visible = True
  204.         ctlSE.Visible = True
  205.         ctlNW.Left = pbBack.Width * 0.05
  206.         ctlNW.Top = pbBack.Height * 0.05
  207.         ctlNW.Width = pbBack.Width * 0.6
  208.         ctlNW.Height = pbBack.Height * 0.6
  209.         ctlSE.Left = ctlNW.Width + 1
  210.         ctlSE.Top = ctlNW.Height + 1
  211.     Else
  212.         pbBack.Visible = False
  213.         Set ctlNW.Container = Me
  214.         Set ctlSE.Container = Me
  215.         ctlNW.Left = Width * 0.05
  216.         ctlNW.Top = Height * 0.05
  217.         ctlNW.Width = Width * 0.6
  218.         ctlNW.Height = Height * 0.6
  219.         ctlSE.Left = ctlNW.Width + 1
  220.         ctlSE.Top = ctlNW.Height + 1
  221.         ctlNW.Visible = True
  222.         ctlSE.Visible = True
  223.     End If
  224.     
  225.     Dim fAuto As Boolean, fVertical As Boolean, picDrag As StdPicture
  226.     fAuto = mnuAutoSize.Checked
  227.     fVertical = mnuVertical.Checked
  228.     
  229.     On Error Resume Next
  230.     split.Create LeftControl:=ctlNW, _
  231.                  RightControl:=ctlSE, _
  232.                  Vertical:=fVertical, _
  233.                  BorderPixels:=4, _
  234.                  AutoBorder:=fAuto, _
  235.                  Resizeable:=True, _
  236.                  Percent:=50
  237.     If Err Then MsgBox "Can't create splitter"
  238. End Sub
  239.  
  240. ' Normally events simply pass through four simple event handlers,
  241. ' but multiple controls and options complicate things here
  242. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  243.     If Not mnuPicture.Checked Then
  244.         split.Splitter_MouseDown Button, Shift, x, y
  245.     End If
  246. End Sub
  247.  
  248. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  249.     If Not mnuPicture.Checked Then
  250.         split.Splitter_MouseMove Button, Shift, x, y
  251.     End If
  252. End Sub
  253.  
  254. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  255.     If Not mnuPicture.Checked Then
  256.         split.Splitter_MouseUp Button, Shift, x, y
  257.     End If
  258. End Sub
  259.  
  260. Private Sub Form_Resize()
  261.     If Not mnuPicture.Checked Then split.Splitter_Resize
  262. End Sub
  263.  
  264. Private Sub pbBack_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  265.     If mnuPicture.Checked Then
  266.         split.Splitter_MouseDown Button, Shift, x, y
  267.     End If
  268. End Sub
  269.  
  270. Private Sub pbBack_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  271.     If mnuPicture.Checked Then
  272.         split.Splitter_MouseMove Button, Shift, x, y
  273.     End If
  274. End Sub
  275.  
  276. Private Sub pbBack_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  277.     If mnuPicture.Checked Then
  278.         split.Splitter_MouseUp Button, Shift, x, y
  279.     End If
  280. End Sub
  281.  
  282. Private Sub pbBack_Resize()
  283.     If mnuPicture.Checked Then split.Splitter_Resize
  284. End Sub
  285.  
  286.  
  287.  
  288.